
package com.kabao.oms.config;

import com.alibaba.druid.filter.stat.MergeStatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.render.ViewType;
import com.kabao.oms.controller.OMSOrder;
import com.kabao.oms.controller.OMSUserLogin;
import com.kabao.oms.controller.OMSlogin;
import com.kabao.oms.model.Cards;
import com.kabao.oms.model.UserModel;

/**
 *
 * OMSconfig
 * 
 * zhangyi
 * zhangyi

 * 
 * @version 1.0.0
 *
 */
public class OMSconfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		// TODO Auto-generated method stub
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		me.setEncoding("utf-8");
	}

	@Override
	public void configRoute(Routes me) {
		// TODO Auto-generated method stub
		me.add("/login",OMSlogin.class);
		me.add("/card",OMSOrder.class);
		me.add("/ ",OMSlogin.class);
		me.add("/userLogin",OMSUserLogin.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO Auto-generated method stub
//		C3p0Plugin cp = new C3p0Plugin("jdbc:mysql://localhost:3306/test", "root", "root");
//		me.add(cp);
//		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
//		me.add(arp);

		DruidPlugin druidPlugin = new DruidPlugin("jdbc:mysql://localhost:3306/test", "root", "root");
		druidPlugin.addFilter(new MergeStatFilter());
		druidPlugin.setMaxActive(150);
		WallFilter wall = new WallFilter();
		wall.setDbType("mysql");
		druidPlugin.addFilter(wall);
		me.add(druidPlugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
		me.add(arp);
		
		arp.setContainerFactory(new CaseInsensitiveContainerFactory());
		arp.addMapping("t_card_info",Cards.class);
		arp.addMapping("t_user","uid", UserModel.class);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
		// TODO Auto-generated method stub
		me.add(new ContextPathHandler("baseUrl"));
	}

}
